package net.lzzy.practices.web.handler;


import org.aspectj.weaver.patterns.HasThisTypePatternTriedToSneakInSomeGenericOrParameterizedTypePatternMatchingStuffAnywhereVisitor;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Administrator
 */
@ControllerAdvice
public class PracticeExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    public ModelAndView handleBusinessException(HttpServletRequest request, BusinessException e){
        String errInfo = "业务异常: " + e.getErrInfo();
        ModelAndView mv = new ModelAndView();
        mv.addObject( "title", errInfo);
        mv.addObject( "url", request.getRequestURL().toString());
        mv.addObject( "exception",e);
        mv.setViewName("error/error");
        return mv;
    }

    @ExceptionHandler(Exception.class)
    public ModelAndView handleException(HttpServletRequest request, Exception e){

        ModelAndView mv = new ModelAndView();
        mv.addObject( "title", "非业务异常");
        mv.addObject( "url", request.getRequestURL().toString());
        mv.addObject( "exception",e);
        mv.setViewName("error/error");
        return mv;
    }
}
